package vehement.game.entities;


import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;

import vehement.game.AI.Path;
import vehement.game.graphics.Ob;
import vehement.game.interfaces.Actor;

public class Critter implements Actor {
	private static float minDist = 0.5f;
	private float speed = 0.5f;
	private float rotation;
	private float rotPerSec;
	
	
	public Vector3f location;
	public Vector3f destination;
	//private Vector3f location;
	
	//A path to hold the immediate path
	public Path path;
	
	
	public Critter(){
		rotation = 0.f;
		rotPerSec = 30.f;
		location = new Vector3f(0.f, 0.f, 0.f);
	}
	
	public void draw() {
		GL11.glPushMatrix();
		GL11.glTranslatef(location.x, location.y, location.z);
		GL11.glRotatef(rotation, 0, 0, 1);
		GL11.glCallList(Ob.cubeCL);
		GL11.glPopMatrix();
		
	}

	public void update(float delta) {
		//This spins
		rotation += rotPerSec * delta;
		if (rotation > 360.f){
			rotation = rotation % 360.f;
		}else if(rotation < 0.f){
			rotation = rotation % 360.f;
			rotation =+ 360.f;
		}
		//move toward primary goal (like attack player)
		Vector3f heading = new Vector3f(0,0,0); 
		
		//if within distance from goal, find a new goal
		if (destination != null){
			
			Vector3f.sub(destination, location, heading);
//			location.distanceSquared(destination)
			if (heading.lengthSquared()  <= minDist){
				//path.peek();
				//find a new destination'
				if(path.hasNext()){
					//if we have a path, find the next node
					destination.x = path.peek().getX();
					destination.y = path.remove().getY();
					destination.z = 0;
				}else{
					//find a new path using the aStar() in world
				}
			}
		} else{
			//we are far away, so lets go toward it
			//location = location +  heading;
		}
		//This moves to the next Path location		
	}
}
